package com.coolingme.editor;

/**
 * 编辑器，发起人角色
 *
 * @author wangyue
 * @date 2020-09-26 17:43
 */
public class Editor {

    /**
     * 标题
     */
    private String title;

    /**
     * 内容
     */
    private String content;

    public Editor(String title, String content) {
        this.title = title;
        this.content = content;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    /**
     * 保存到备忘录
     *
     * @return 备忘录
     */
    public ArticleMemento saveToMemento() {
        return new ArticleMemento(this.title, this.content);
    }

    /**
     * 从备忘录中恢复
     *
     * @param memento 被恢复的备忘录
     */
    public void undoFromArticleMemento(ArticleMemento memento) {
        this.title = memento.getTitle();
        this.content = memento.getContent();
    }

    @Override
    public String toString() {
        return "备忘录{" +
                "标题='" + title + '\'' +
                ", 文章内容='" + content + '\'' +
                '}';
    }

}
